package com.edu.api.entity.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

/**
 * @description: 描述
 * @author: xnylh
 * @createDate: 2023/1/5 0005 16:24
 */
public class TimeUtil {

    public static String getTime(){
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
        Date date = new Date(System.currentTimeMillis());
        return formatter.format(date);
    }

    public static Date getTimeDate(){
        LocalDateTime dt  = LocalDateTime.now();
        return Date.from(dt.toInstant(ZoneOffset.of("+8")));
    }

    public static Date valueOf(String time){
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return ft.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
            System.err.println("String转date错误");
            return null;
        }
    }

}
